﻿using System;
using DDDProjectSample.Domain;
using DDDProjectSample.Domain.Repositories;
using Castle.Facilities.NHibernateIntegration;
using NHibernate;
using NHibernate.Expression;

namespace DDDProjectSample.Infrastructure.Repositories
{
    public class MemberRepository : BaseRepository<Member>, IMemberRepository
    {
        /// <summary>
        /// Creates a new instance of class MemberRepository
        /// </summary>
        /// <param name="sessionManager">The Nhibernate Session Manager</param>
        public MemberRepository(
            ISessionManager sessionManager) : base(sessionManager)
        {
        }

        #region IMemberRepository Members

        public Member GetByLogin(string login)
        {
            using (ISession session = SessionManager.OpenSession())
            {
                return session.CreateCriteria(typeof(Member))
                            .Add(Expression.Eq("Login", login))
                            .UniqueResult<Member>();
            }
        }

        #endregion
    }
}
